package com.example.demo.web;

import com.example.demo.config.session.LoginUser;
import com.example.demo.config.session.PassToken;
import com.example.demo.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author
 * 用户 web层
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @GetMapping("/noNeedToken")
    @ApiOperation(value = "不需要token")
    @PassToken
    public String noNeedToken(){
        log.info("加了passToken注解，不需要token验证");
        return "加了passToken注解，不需要token验证";
    }

    @GetMapping("/noToken")
    @ApiOperation(value = "没有携带token")
    public String noToken(){
        log.info("没有携带token，拒绝访问");
        return "没有携带token，拒绝访问";
    }

    @GetMapping("/withToken")
    @ApiOperation(value = "携带了token")
    public User withToken(@LoginUser User user){
        log.info("携带token，可以访问");
        log.info("user：{}", user.toString());
        return user;
    }

}
